package io.renren.modules.sys.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.Query;
import io.renren.modules.sys.dao.SysGoodsDao;
import io.renren.modules.sys.entity.SysGoodsEntity;
import io.renren.modules.sys.service.SysGoodsService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import io.renren.common.utils.PageUtils;


@Service("sysGoodsService")
public class SysGoodsServiceImpl extends ServiceImpl<SysGoodsDao, SysGoodsEntity> implements SysGoodsService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String name = (String)params.get("name");
        Long goodsId = (Long)params.get("goodsId");

        Page<SysGoodsEntity> page = this.selectPage(
                new Query<SysGoodsEntity>(params).getPage(),
                new EntityWrapper<SysGoodsEntity>()
                        .like(StringUtils.isNotBlank(name),"name", name)
                        .eq(goodsId != null,"goods_id", goodsId)
        );

        return new PageUtils(page);
    }

}
